<template>
  <div>
    <el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="添加关系">
      <el-row :gutter="15">
        <el-form ref="elForm" :model="relation" :rules="rules" size="medium" label-width="100px">
          <el-col :span="23">
            <el-form-item label="关系名称" prop="relationName">
              <el-input v-model="relation.relationName" placeholder="请输入关系名称" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="关系类型" prop="relationType">
              <el-select v-model="relation.relationType" placeholder="请选择关系类型" clearable
                         :style="{width: '100%'}">
                <el-option v-for="(item, index) in relationTypeOptions" :key="index" :label="item.label"
                           :value="item.value" :disabled="item.disabled"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { updateRelation} from "@/api/relation";

export default {
  inheritAttrs: false,
  components: {},
  props: {relation:{}},
  data() {
    return {
      rules: {
        relationName: [{
          required: true,
          message: '请输入关系名称',
          trigger: 'blur'
        }],
        relationType: [{
          required: true,
          message: '请选择关系类型',
          trigger: 'change'
        }],
      },
      relationTypeOptions: [{
        "label": "人员关系",
        "value": '0'
      }, {
        "label": "工作关系",
        "value": '1'
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onOpen() {},
    onClose() {
      this.$refs['elForm'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
    },
    handelConfirm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        updateRelation(this.relation).then(res=>{
          if (res.code===200){
            this.$message.success("更新成功")
            this.$emit("addResult")
          }
        })
        this.close()
      })
    },
  }
}

</script>
<style>
</style>
